package com.tian.controller;

import com.tian.common.CommonResult;
import com.tian.message.SendEmailMessage;
import com.tian.service.SendEmailService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * {@code @description:} 发送邮件控制器
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-12-09 10:46
 * {@code @version:} 1.0
 */
@Slf4j
@RestController
@RequestMapping("/send")
@Api(tags = "发送短信 控制器")
public class SendEmailController {

    @Resource
    private SendEmailService sendEmailService;

    @PostMapping("/email")
    public CommonResult<String> sendEmail(@RequestBody SendEmailMessage sendEmailMessage) {
        try {
            log.info("发送邮件请求参数：{}", sendEmailMessage);
            sendEmailService.sendEmail(sendEmailMessage);
            return CommonResult.success("发送邮件成功");
        } catch (Exception e) {
            log.error("发送邮件失败：", e);
        }
        return CommonResult.failed("发送邮件失败");
    }
}
